local ddcl = require "ddcl"
ddcl.init()
ddcl.open_all()

local service = require "ddcl.service"
local http_client = require "ddcl.http.client"
local inspect = require "ddcl.inspect"
local http_server = require "ddcl.http.server"

service.start(function()
    print("start", service.self())


    local req = http_client({
        host = "www.baidu.com",
        port = 80,
    })


    local header = {}
    table.insert(header, "Accept: */*")
    table.insert(header, "User-Agent: curl/7.58.0")


    local now = ddcl.now()
    for i = 1, 0 do
        local ii = i
        service.fork(function()
            local res = req.get("/", header, "")
            print(inspect(res))
            now = ddcl.now()
        end)

    end

    local s = http_server({
        host = "0.0.0.0",
        port = 8002,
        forward = true,
        max_header_len = 2048,
        check_header_fn = function(request)
            return true
        end,
        execute_fn = function(c, request, response)
            response.resp("hello")
        end,
    })
    s.listen()

    print("end:")
end)
